// import com.alibaba.druid.sql.ast.SQLExpr_ptr;
// import com.alibaba.druid.sql.ast.SQLName_ptr;
// import com.alibaba.druid.sql.ast.SQLStatementImpl;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.ArrayList;
// import java.util.List;

#include "SQLCloneTableStatement.h"
#include "../../visitor/SQLASTVisitor.h"
#include "../../../utils/instanceof.h"
#include "SQLExprTableSource.h"

SQLCloneTableStatement::SQLCloneTableStatement()
{
  partitions = std::make_shared<std::list<SQLAssignItem_ptr>>();
}

SQLCloneTableStatement::SQLCloneTableStatement(SQLExpr_ptr to)
{
  this->setTo(to);
  partitions = std::make_shared<std::list<SQLAssignItem_ptr>>();
}

SQLExprTableSource_ptr SQLCloneTableStatement::getTo()
{
  return to;
}

void SQLCloneTableStatement::setTo(SQLExprTableSource_ptr to)
{
  if (to != nullptr)
  {
    to->setParent(SharedObject(SQLCloneTableStatement));
  }
  this->to = to;
}

void SQLCloneTableStatement::setTo(SQLExpr_ptr to)
{
  this->setTo(SQLExprTableSource_ptr(new SQLExprTableSource(to)));
}

SQLAssignItem_list_ptr SQLCloneTableStatement::getPartitions()
{
  return partitions;
}

SQLName_ptr SQLCloneTableStatement::getToName()
{
  if (to == nullptr)
  {
    return nullptr;
  }

  SQLExpr_ptr expr = to->expr;

  if (instanceof <SQLExpr, SQLName>(expr))
  {
    return std::dynamic_pointer_cast<SQLName>(expr);
  }

  return nullptr;
}

SQLExprTableSource_ptr SQLCloneTableStatement::getFrom()
{
  return from;
}

void SQLCloneTableStatement::setFrom(SQLExprTableSource_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLCloneTableStatement));
  }
  this->from = x;
}

void SQLCloneTableStatement::setFrom(SQLName_ptr x)
{
  this->setFrom(SQLExprTableSource_ptr(new SQLExprTableSource(x)));
}

BOOL_ptr SQLCloneTableStatement::isIfExistsOverwrite()
{
  return ifExistsOverwrite;
}

void SQLCloneTableStatement::setIfExistsOverwrite(BOOL_ptr ifExistsOverwrite)
{
  this->ifExistsOverwrite = ifExistsOverwrite;
}

BOOL_ptr SQLCloneTableStatement::isIfExistsIgnore()
{
  return ifExistsIgnore;
}

void SQLCloneTableStatement::setIfExistsIgnore(BOOL_ptr ifExistsIgnore)
{
  this->ifExistsIgnore = ifExistsIgnore;
}

// @Override
void SQLCloneTableStatement::accept0(SQLASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(SQLCloneTableStatement)))
  {
    acceptChild(visitor, from);
    acceptChild(visitor, to);
  }
  visitor->endVisit(SharedObject(SQLCloneTableStatement));
}
